import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import {isLogin} from '../utils/auth'

let router = new VueRouter
({
  mode:"history", 
  routes

})

router.beforeEach((to, from, next) => {
  // 判断是否去登录界面，是：判断有没有登录，有则拦截，无则跳登录界面，否：判断有没有登录，有则跳转，无则跳登陆界面
  let Auth=isLogin()
  if(to.path==='/login')
  {
    if(Auth){
      next('/')
    }else{
      next()
    }
  }else{
    if(Auth){
      next()
    }else{
      next('/login')
    }

  }
})

Vue.use(VueRouter);

export default router